package com.example.fw;

public class ContactHelper extends HelpersBase {

        public ContactHelper(ApplicationManager applicationManager) {
                super(applicationManager);
        }

        public void createContact(Contact contact) {
                initContactCreation();
                fillContactForm(contact);
                confirmContactCreation();
        }

        public void initContactCreation() {
                manager.getAutoItHelper()
                	.winWaitAndActivate("AddressBook Portable", "", 5000)
                    .click("Add")
                    .winWaitAndActivate("Add Contact", "", 5000);
        }
        
        public void fillContactForm(Contact contact) {
                manager.getAutoItHelper()
                .send("TDBEdit12", contact.firstName)
                .send("TDBEdit11", contact.lastName);
        }

        public void confirmContactCreation() {
                manager.getAutoItHelper().click("Save")
                .winWaitAndActivate("AddressBook Portable", "", 5000);
        }

		public Contact getFirstContact() {
			manager.getAutoItHelper().focus("TListView1")
			.winWaitAndActivate("AddressBook Portable", "", 5000)
				.click("{DOWN}{SPACE}")
				.click("Edit")
				.winWaitAndActivate("Update Contact", "", 5000);
			
			Contact contact = new Contact() 
				.setFirstName(manager.getAutoItHelper().getText("TDBEdit12"))
				.setLastName(manager.getAutoItHelper().getText("TDBEdit12"));
            
			manager.getAutoItHelper()
            	.click("Cancel")
            	.winWaitAndActivate("AddressBook Portable", "", 5000);
			return null;
			
		}

		public void deleteContact() {
			manager.getAutoItHelper().focus("TListView1")
			.winWaitAndActivate("AddressBook Portable", "", 5000)
				.click("{DOWN}{SPACE}")
				.click("Delete")
				.winWaitAndActivate("Confirm", "", 5000)
				.click("Yes")
				.winWaitAndActivate("AddressBook Portable", "", 5000);
			
		}
}

